<%@ page language="java" import="java.util.*,news.dao.*,news.entity.*,utilu.*"
	pageEncoding="utf-8"%>
<!-- 这个文档用来处理编辑的 和增加的新闻的 -->
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'domodifynew.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%
		request.setCharacterEncoding("utf-8");
		//获取摘要
		String nsummary = request.getParameter("nsummary");
		//获取序号
		
			NewsDao nw = new NewsDao();
			//获取分类
			int ntid=Integer.parseInt(request.getParameter("ntid"));
			//获取作者
				String nauthor=request.getParameter("nauthor");
			//获取内容
				String ncontent=request.getParameter("ncontent");
			//标题
				String ntitle=request.getParameter("ntitle");
		News news = new News();
		news.setNtid(ntid);
	
		news.setNtitle(ntitle);
		news.setNauthor(nauthor);
		news.setNcontent(ncontent);
		news.setNsummary(nsummary);
		//修改时间
		Date da = new Date();
		news.setNmodifyDate(DBUtil.datestring(da));
//添加时间
		 news.setNcreateDate(DBUtil.datestring(da));
	
	//获取请求判断是添加还是修改
	String claim=request.getParameter("claim");
	if(claim.equals("modifynew")){
	//修改新闻
	int nid = Integer.parseInt(request.getParameter("nid"));
		news.setNid(nid);
	int bo=	nw.amendnews(news);
	if(bo>0){%>
	<script type="text/javascript">
	alert("修改成功！");location = "admin.jsp";
	</script>
	
<%	}else{%>
	<script type="text/javascript">
	alert("修改失败！");location = "admin.jsp";
	</script>
	<% }
		}else{
			int boo=nw.addnews(news);
	if(boo>0){%>
	<script type="text/javascript">
	alert("添加成功！");location = "admin.jsp";
	</script>
	
<%	}else{%>
	<script type="text/javascript">
	alert("添加失败！");location = "admin.jsp";
	</script>
	<% }
		
		
		
		
		}
	%>

</body>
</html>
